package top.lingkang.finalgateway.admin.controller;

import cn.hutool.core.lang.Assert;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.MethodType;
import top.lingkang.finalgateway.admin.dto.ResponseResult;
import top.lingkang.finalgateway.admin.dto.ResponseResultPage;
import top.lingkang.finalgateway.admin.entity.ActionLogEntity;
import top.lingkang.finalgateway.admin.mapper.ActionLogMapper;
import top.lingkang.finalgateway.admin.param.LogParam;
import top.lingkang.finalvalidated.core.ValidObject;
import top.lingkang.mm.page.PageHelper;
import top.lingkang.mm.page.PageInfo;

import java.util.List;

/**
 * @author lingkang
 * @create by 2024/5/14 16:32
 */
@Controller
@Mapping("/api/action")
public class ActionController {
    @Inject
    private ActionLogMapper actionLogMapper;

    @Mapping(value = "/log", method = MethodType.GET)
    public Object log(@ValidObject LogParam param) {
        PageHelper.startPage(param.getPage(), param.getSize());
        List<ActionLogEntity> list = actionLogMapper.list(param);
        PageInfo page = PageHelper.getPage();
        return new ResponseResultPage<>().setData(list)
                .setPage(param.getPage())
                .setSize(param.getSize())
                .setTotal(page.getTotal());
    }

    @Mapping(value = "/get", method = MethodType.GET)
    public Object get(String id) {
        Assert.notBlank(id, "id不能为空");
        return new ResponseResult<>().setData(actionLogMapper.selectById(id));
    }
}
